import request from '../request'

// 学生管理相关API
export const studentApi = {
  // 分页查询学生信息
  getStudentPage(params) {
    return request({
      url: '/students/page',
      method: 'get',
      params
    })
  },
  
  // 获取学生详情
  getStudentDetail(studentId) {
    return request({
      url: `/students/${studentId}`,
      method: 'get'
    })
  },
  
  // 新增学生
  addStudent(data) {
    return request({
      url: '/students',
      method: 'post',
      data
    })
  },
  
  // 更新学生信息
  updateStudent(studentId, data) {
    return request({
      url: `/students/${studentId}`,
      method: 'put',
      data
    })
  },
  
  // 删除学生
  deleteStudent(studentId) {
    return request({
      url: `/students/${studentId}`,
      method: 'delete'
    })
  },
  
  // 批量删除学生
  batchDeleteStudents(studentIds) {
    return request({
      url: '/students/batch',
      method: 'delete',
      data: { studentIds }
    })
  },
  
  // 根据班级查询学生
  getStudentsByClass(classId) {
    return request({
      url: `/students/class/${classId}`,
      method: 'get'
    })
  },
  
  // 根据身份证号查询学生
  getStudentByIdCard(idCard) {
    return request({
      url: `/students/idcard/${idCard}`,
      method: 'get'
    })
  },
  
  // 学生转班
  transferStudent(studentId, newClassId) {
    return request({
      url: `/students/${studentId}/transfer`,
      method: 'put',
      params: { newClassId }
    })
  },
  
  // 批量转班
  batchTransferStudents(studentIds, newClassId) {
    return request({
      url: '/students/batch/transfer',
      method: 'put',
      data: { studentIds, newClassId }
    })
  },
  
  // 更新学生状态
  updateStudentStatus(studentId, status) {
    return request({
      url: `/students/${studentId}/status`,
      method: 'put',
      params: { status }
    })
  },
  
  // 批量更新学生状态
  batchUpdateStudentStatus(studentIds, status) {
    return request({
      url: '/students/batch/status',
      method: 'put',
      data: { studentIds, status }
    })
  },
  
  // 按班级统计学生数量
  getStatisticsByClass() {
    return request({
      url: '/students/statistics/class',
      method: 'get'
    })
  },
  
  // 按年级统计学生数量
  getStatisticsByGrade() {
    return request({
      url: '/students/statistics/grade',
      method: 'get'
    })
  },
  
  // 按状态统计学生数量
  getStatisticsByStatus() {
    return request({
      url: '/students/statistics/status',
      method: 'get'
    })
  },
  
  // 模糊搜索学生
  searchStudents(params) {
    return request({
      url: '/students/search',
      method: 'get',
      params
    })
  },
  
  // 导入学生数据
  importStudents(file) {
    const formData = new FormData()
    formData.append('file', file)
    return request({
      url: '/students/import',
      method: 'post',
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },
  
  // 导出学生数据
  exportStudents(params) {
    return request({
      url: '/students/export',
      method: 'get',
      params,
      responseType: 'blob'
    })
  },
  
  // 生成学生ID
  generateStudentId() {
    return request({
      url: '/students/generate-id',
      method: 'get'
    })
  },
  
  // 验证学生信息
  validateStudent(data) {
    return request({
      url: '/students/validate',
      method: 'post',
      data
    })
  }
}